package com.hardware.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hardware.common.R;
import com.hardware.dto.ShopDto;
import com.hardware.entity.Category;
import com.hardware.entity.Shop;
import com.hardware.service.CategoryService;
import com.hardware.service.PurchaseService;
import com.hardware.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

import static com.hardware.utils.RedisConstants.CACHE_STOCK_KEY;

/**
 * 商品库存预警
 */
@RestController
@RequestMapping("/stock")
@Slf4j
public class StockController {
    @Autowired
    private ShopService shopService;
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 添加库存
     * @param shopDto
     * @return
     */
    @PutMapping("/shopStock")
    @CacheEvict(value = "cache:purchase:",allEntries = true)
    public R<String> addStock(@RequestBody ShopDto shopDto){
        purchaseService.add(shopDto);
        return R.success("已将商品添加到采购订单中");
    }

}
